'use client'; import './price-chart.scss'; import { Area, AreaChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts'; import type { StockPriceRow } from '@/types/stock'; import { changeDirection, formatNumber } from '@/lib/utils/stock'; // 종목 상세 시세 그래프 — 최근 종가 시계열(과거→최신) 영역 차트. stock-detail__basis 바로 하단. // 색은 래퍼 dir 클래스(.stock-chart--up/down/flat)의 CSS color 를 currentColor 로 상속 // (recharts stroke/fill 은 SVG presentation attribute 라 var() 미해석 → currentColor 사용). type Props = { // GetDetail.recentPrices — 최신순(newest-first) prices: StockPriceRow[]; name: string; }; export default function StockPriceChart({ prices, name }: Props) { // 데이터 2개 미만이면 미표시 (하단 일별 시세 표로 대체) if (!prices || prices.length < 2) { return null; } // 과거→최신 순서로 뒤집어 종가 시계열 구성 const series = [...prices].reverse().map(p => ({ date: p.tradingDate, close: p.close })); const dir = changeDirection(series[series.length - 1].close - series[0].close); return (
최근 {series.length}일 종가 추이
{ const n = Array.isArray(value) ? Number(value[0]) : Number(value); return [formatNumber(Number.isFinite(n) ? n : null), '종가']; }} labelFormatter={(label) => String(label)} />
); }